//
//  XTCAppointmentInformationShow.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/11.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XTCAppointmentInformationShow.h"
#import "XXTool.h"


@interface XTCAppointmentInformationShow ()

@property (nonatomic) UIView *contentBackground;

@property (nonatomic) UIImageView *userHead;

@property (nonatomic) UILabel *apTime;

@property (nonatomic) DKButton *agree;

@property (nonatomic) DKButton *refuse;

@property (nonatomic) UIImageView *sureAp;

@end

@implementation XTCAppointmentInformationShow
{
    CGFloat buttonWidth;
    CGFloat buttonHeight;
}

-(UIView*)contentBackground
{
    if (_contentBackground==nil)
    {
        _contentBackground = [[UIView alloc] init];
        _contentBackground.backgroundColor = [UIColor whiteColor];
        _contentBackground.layer.shadowOpacity = 1;
        _contentBackground.layer.shadowColor = [UIColor colorWithRed:214/255.0 green:215/255.0 blue:216/255.0 alpha:1.0].CGColor;
        _contentBackground.layer.shadowOffset = CGSizeMake(0,1);
        _contentBackground.layer.shadowRadius = 2;
        _contentBackground.layer.masksToBounds = NO;
        [self addSubview:_contentBackground];
    }
    return _contentBackground;
}

-(UIImageView*)userHead
{
    if (_userHead==nil)
    {
        _userHead = [[UIImageView alloc] init];
        _userHead.contentMode = UIViewContentModeScaleAspectFill;
        _userHead.image = [UIImage imageNamed:@"消息默认头像"];
        _userHead.clipsToBounds = YES;
        [_contentBackground addSubview:_userHead];
    }
    return _userHead;
}

-(UIImageView*)sureAp
{
    if (_sureAp==nil)
    {
        _sureAp = [[UIImageView alloc] init];
        _sureAp.image = [UIImage imageNamed:@"预约确认"];
        _sureAp.contentMode = UIViewContentModeScaleAspectFit;
        [_contentBackground addSubview:_sureAp];
    }
    return _sureAp;
}

-(UILabel*)apTime
{
    if (_apTime==nil)
    {
        _apTime = [[UILabel alloc] init];
        _apTime.font = [XXTool boldSystemFontOfSize:15];
        _apTime.textColor = [UIColor blackColor];
        _apTime.numberOfLines = 0;
        [_contentBackground addSubview:_apTime];
    }
    return _apTime;
}

-(DKButton*)agree
{
    if (_agree==nil)
    {
        _agree = [[DKButton alloc] init];
        _agree.text = NSLocalizedString(@"同意", nil);
        _agree.layer.borderColor = [XXTool colorWithProject].CGColor;
        _agree.layer.borderWidth = 0.5f;
        [_agree setColor:[UIColor whiteColor] ForState:DKButtonStateNormal];
        _agree.textColor = [XXTool colorWithProject];
        _agree.layer.cornerRadius = 5;
        [_agree addTarget:self Select:@selector(clickArgeeButton) ForEvent:DKButtonEventPressedEnd];
        [_contentBackground addSubview:_agree];
    }
    return _agree;
}

-(DKButton*)refuse
{
    if (_refuse==nil)
    {
        _refuse = [[DKButton alloc] init];
        _refuse.text = NSLocalizedString(@"拒绝", nil);
        _refuse.layer.borderColor = [UIColor grayColor].CGColor;
        _refuse.layer.borderWidth = 0.5f;
        [_refuse setColor:[UIColor whiteColor] ForState:DKButtonStateNormal];
        _refuse.textColor = [UIColor grayColor];
        _refuse.layer.cornerRadius = 5;
        [_refuse addTarget:self Select:@selector(clickRefuseButton) ForEvent:DKButtonEventPressedEnd];
        [_contentBackground addSubview:_refuse];
    }
    return _refuse;
}

-(void)setUseType:(XTCAppointmentInformationShowType)useType
{
    _useType = useType;
    [self refreshLayout:self.frame];
}

-(void)initParameter
{
    buttonWidth = 75;
    buttonHeight = 30;
}

-(void)initUI
{
}

-(void)refreshLayout:(CGRect)frame
{
    CGFloat topGap = (105-buttonHeight*2-14)/2;
    
    self.contentBackground.frame = CGRectMake(0, 0, frame.size.width
                                              , 105);
    _contentBackground.layer.shadowPath = [UIBezierPath bezierPathWithRect:_contentBackground.frame].CGPath;
    
    self.userHead.frame = CGRectMake(20
                                     , (105-60)/2
                                     , 60
                                     , 60);
    _userHead.layer.cornerRadius = _userHead.frame.size.width/2;
    
    self.apTime.frame = CGRectMake(_userHead.frame.size.width+_userHead.frame.origin.x+20
                                   , 0
                                   , frame.size.width-(_userHead.frame.size.width+_userHead.frame.origin.x+20*2+95)
                                   , _contentBackground.frame.size.height);
    if (_useType==XTCAppointmentInformationShowMessage)
    {
        self.agree.frame = CGRectMake(_apTime.frame.size.width+_apTime.frame.origin.x+20
                                      , topGap
                                      , buttonWidth
                                      , buttonHeight);
        self.refuse.frame = CGRectMake(_agree.frame.origin.x
                                       , _agree.frame.size.height+_agree.frame.origin.y+14
                                       , buttonWidth
                                       , buttonHeight);
    }
    else if (_useType==XTCAppointmentInformationShowRecord)
    {
        self.sureAp.frame = CGRectMake(_apTime.frame.size.width+_apTime.frame.origin.x+49
                                       , (105-22)/2
                                       , 22
                                       , 22);
    }
}

-(void)clickRefuseButton
{
    if ([_delegate respondsToSelector:@selector(appointmentInformationShowClickCancelButtonWithCell:)])
    {
        [_delegate appointmentInformationShowClickCancelButtonWithCell:self];
    }
}

-(void)clickArgeeButton
{
    if ([_delegate respondsToSelector:@selector(appointmentInformationShowClickAgreeButtonWithCell:)])
    {
        [_delegate appointmentInformationShowClickAgreeButtonWithCell:self];
    }
}

-(void)setCellWithData:(XMLMessageModel *)model
{
    [_userHead setImageWithUrl:model.headphoto placerHolder:[UIImage imageNamed:@"消息默认头像"]];
    
    NSString * appointmentString = NSLocalizedString(@"预约时间", nil);
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\r\r%@",appointmentString,[XXTool stampToTimeWithoutYear:model.order_time]]];
    [string addAttributes:@{NSForegroundColorAttributeName:[XXTool colorWithHexString:@"989898"]}
                    range:NSMakeRange(0, appointmentString.length)];
    _apTime.attributedText = string;
}

+(CGFloat)heightForCell
{
    return 105+4;
}

@end
